package com.icow.wms.basic.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.icow.common.annotation.Log;
import com.icow.common.core.controller.BaseController;
import com.icow.common.core.domain.AjaxResult;
import com.icow.common.enums.BusinessType;
import com.icow.wms.basic.domain.ProductDomain;
import com.icow.wms.basic.service.IProductDomainService;
import com.icow.common.utils.poi.ExcelUtil;
import com.icow.common.core.page.TableDataInfo;

/**
 * productController
 * 
 * @author lqq
 * @date 2021-02-02
 */
@RestController
@RequestMapping(value = {"/wms.basic/product", "/api/product"})
public class ProductDomainController extends BaseController
{
    @Autowired
    private IProductDomainService productDomainService;

    /**
     * 查询product列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProductDomain productDomain)
    {
        startPage();
        List<ProductDomain> list = productDomainService.selectProductDomainList(productDomain);
        return getDataTable(list);
    }

    /**
     * 导出product列表
     */
    @Log(title = "product", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductDomain productDomain)
    {
        List<ProductDomain> list = productDomainService.selectProductDomainList(productDomain);
        ExcelUtil<ProductDomain> util = new ExcelUtil<ProductDomain>(ProductDomain.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 获取product详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(productDomainService.selectProductDomainById(id));
    }

    /**
     * 新增product
     */
    @Log(title = "product", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductDomain productDomain)
    {
        return toAjax(productDomainService.insertProductDomain(productDomain));
    }

    /**
     * 修改product
     */
    @Log(title = "product", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductDomain productDomain)
    {
        return toAjax(productDomainService.updateProductDomain(productDomain));
    }

    /**
     * 修改product
     */
    @Log(title = "product", businessType = BusinessType.INSERT)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody ProductDomain productDomain)
    {
        return toAjax(productDomainService.updateProductDomainByCode(productDomain));
    }

    /**
     * 删除product
     */
    @Log(title = "product", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productDomainService.deleteProductDomainByIds(ids));
    }
}
